import java.util.*;
public class BuildSummary {

	public static Summary build(String database, Presult pst)
	{
		Summary sum=new Summary(database);
		HashMap tdf=new HashMap();
		
		if(pst==null)
		{
			System.err.println("The Presult is null");
			return null;
		}
		
		for(int i=0;i<pst.getSize();i++)
		{
			Result result=pst.get(i);
			Set terms=getWordsLynx.runLynx(result.url.toString());
			Iterator it=terms.iterator();
			while(it.hasNext())
			{
				String term=(String)it.next();
				if(tdf.containsKey(term))
				{
					tdf.put(term, new Integer(((Integer)tdf.get(term)).intValue()+1));
				}
				else
				{
					tdf.put(term, new Integer(1));
				}
			}
			
		}
		sum.setMap(tdf);
		return sum;
	} 
}
